﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace JYH.Framework
{
    public class JyhDataType
    {
        public static DataTable GetJyhDataType()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("DBTYPE");
            dt.Columns.Add("DBNAME");
            dt.Columns.Add("DBCONN");
            DataRow dr = dt.NewRow();
            dr["DBTYPE"] = "System.Data.SqlClient";
            dr["DBNAME"] = "Mssql数据库";
            dr["DBCONN"] = "Data Source={0};Initial Catalog={1};User Id={2};Password={3};Connect TimeOut=360";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["DBTYPE"] = "System.Data.OracleClient";
            dr["DBNAME"] = "Oracle数据库";
            dr["DBCONN"] = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT=1521))(CONNECT_DATA=(SERVICE_NAME={1})));User Id={2};Password={3}";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["DBTYPE"] = "System.Data.SQLite";
            dr["DBNAME"] = "SQLite数据库";
            dr["DBCONN"] = "Data Source={0};Version=3;";
            dt.Rows.Add(dr);
            dr = dt.NewRow();
            dr["DBTYPE"] = "MySql.Data.MySqlClient";
            dr["DBNAME"] = "MySql数据库";
            dr["DBCONN"] = "Server={0};Database={1};Uid={2};Pwd={3};Connection Timeout=360;";
            dt.Rows.Add(dr);
          
            return dt;
        }
        public static string GetDbConn(string DbType)
        {
            string dbconn = string.Empty;
            DataTable dt = GetJyhDataType();
            foreach (DataRow dr in dt.Rows)
            {
                if (string.Equals(dr["DBTYPE"].ToString(), DbType))
                {
                    dbconn = dr["DBCONN"].ToString();
                    break;
                }
            }
            return dbconn;
        }
        
    }
}
